package com.lepu.app.main.bean;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class BeanSample {

    public static ArrayList<BeanSample> parseListInfo(String dataString) {
        String result = "";
        try {
            JSONObject jsonObject = new JSONObject(dataString);
            JSONObject obj1 = (JSONObject) jsonObject.get("Result");
            JSONArray jsonArray = obj1.getJSONArray("ListInfo");

            result = jsonArray.toString();
        } catch (JSONException e) {
            e.printStackTrace();
        }

        Gson gson = new Gson();
        ArrayList<BeanSample> dataList = gson.fromJson(result,
                new TypeToken<List<BeanSample>>() {
                }.getType());
        return dataList;
    }

    /*
	 * 解析数据
	 */
    public static BeanSample parseDetailInfo(String dataString)
    {
        String result = "";
        try {
            JSONObject jsonObject = new JSONObject(dataString);
            JSONObject obj1 = (JSONObject) jsonObject.get("Result");
            JSONObject obj2 = (JSONObject) obj1.get("DetailInfo");

            result = obj2.toString();
        } catch (JSONException e) {
            e.printStackTrace();
        }

        Gson gson = new Gson();
        BeanSample item = gson.fromJson(result,
                new TypeToken<BeanSample>() {
                }.getType());
        return item;
    }
}
